// src/scenarios/building_automation.rs

//! 建筑自动化场景
//! 支持建筑自动化的语义转换和OPC UA模型构建

use crate::scenarios::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// 建筑自动化场景
pub struct BuildingAutomationScenario {
    config: ScenarioConfig,
}

impl BuildingAutomationScenario {
    pub fn new() -> Self {
        Self {
            config: ScenarioConfig {
                name: Some("建筑自动化语义转换场景".to_string()),
                description: Some("支持建筑自动化数据的语义转换和OPC UA模型构建，包括楼宇控制、暖通空调、照明系统等".to_string()),
                custom_rules: None,
                extensions: HashMap::new(),
            },
        }
    }

    pub fn new_with_config(config: ScenarioConfig) -> Self {
        Self { config }
    }
}

impl Scenario for BuildingAutomationScenario {
    fn name(&self) -> &'static str {
        "Building Automation Semantic Conversion"
    }

    fn description(&self) -> &'static str {
        "建筑自动化语义转换场景，支持楼宇管理数据的语义转换"
    }

    fn industry(&self) -> &'static str {
        "BuildingAutomation"
    }

    fn get_transformation_rules(&self) -> ScenarioTransformationRules {
        ScenarioTransformationRules {
            rule_name: "Building_Automation_General".to_string(),
            data_source_mappings: HashMap::new(),
            unit_conversions: HashMap::new(),
            data_type_mappings: HashMap::new(),
            semantic_mappings: HashMap::new(),
            constraints: vec![],
        }
    }

    fn get_opcua_model_template(&self) -> ScenarioModelTemplate {
        ScenarioModelTemplate {
            template_name: "BuildingAutomationModel".to_string(),
            namespaces: vec![
                "http://opcfoundation.org/UA/".to_string(),
                "http://industryagent.com/building/".to_string(),
            ],
            object_types: vec![],
            variable_types: vec![],
            reference_types: vec![],
        }
    }

    fn get_sample_data(&self) -> Vec<ScenarioSampleData> {
        vec![
            ScenarioSampleData {
                data_id: "hvac_001".to_string(),
                data_source_type: "HuaweiCloudIoT".to_string(),
                raw_data: serde_json::json!({
                    "device_id": "HVAC-001",
                    "location": "办公楼3层",
                    "mode": "Cooling",
                    "setpoint": 24.0,
                    "current_temperature": 26.5,
                    "fan_speed": "Medium",
                    "energy_consumption": 3.2,
                    "timestamp": "2024-01-15T10:30:00Z"
                }),
                expected_opcua: serde_json::json!({"nodeId": "ns=8;i=1001"}),
                description: Some("暖通空调系统数据示例".to_string()),
                category: Some("HVAC".to_string()),
            },
        ]
    }

    fn get_semantic_mappings(&self) -> HashMap<String, String> {
        let mut mappings = HashMap::new();
        mappings.insert("hvac_system".to_string(), "HVACSystem".to_string());
        mappings.insert("lighting_controller".to_string(), "LightingController".to_string());
        mappings
    }
}